package com.insigma.business.qrcode.soldier._bff.impl;

import com.insigma.business.common.utils.CurrentUserUtil;
import com.insigma.business.qrcode.common.util.BizCheckUtil;
import com.insigma.business.qrcode.common.util.SessionUtils;
import com.insigma.business.qrcode.common.vo.BaseResponse;
import com.insigma.business.qrcode.soldier.dto.*;
import com.insigma.business.qrcode.soldier.request.CommonRepresentationRecordInsertRequest;
import com.insigma.business.qrcode.soldier.request.PlacementInfoSearchRequest;
import com.insigma.business.qrcode.soldier._bff.PlacementSoldierInfoBFFProvider;
import com.insigma.business.qrcode.soldier._consumer.PlacementSoldierInfoConsumer;
import com.insigma.business.qrcode.soldier._consumer.SoldierConsumer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Slf4j
@Service
@Component("placementSoldierInfoBFFProvider")
public class PlacementSoldierInfoBFFProviderImpl implements PlacementSoldierInfoBFFProvider {

    @Resource
    SoldierConsumer soldierConsumer;

    @Resource
    PlacementSoldierInfoConsumer placementSoldierInfoConsumer;


    @Override
    public BaseResponse<PlacementSoldierInfoDTO> signInByIdCardOfAlipay() {
        String soldierUserId = CurrentUserUtil.getCurrentUser().getSoldierId();
        SoldierOuterLoginAccountDTO dto = soldierConsumer.getSoldierOuterLoginAccountBySoldierId(soldierUserId).getDto();
        PlacementSoldierInfoInsertRequest request = new PlacementSoldierInfoInsertRequest();
        request.setSoldierId(soldierUserId);
        request.setIdCardNo(dto.getOuterSysCertNo());
        return placementSoldierInfoConsumer.signInByIdCardOrMobile(request);    }

    @Override
    public BaseResponse<PlacementSoldierInfoDTO> getPlacementProcess() {
        return placementSoldierInfoConsumer.getPlacementProcess(CurrentUserUtil.getCurrentUser().getSoldierId());

    }

    @Override
    public BaseResponse<PlacementBatchDTO> viewDeadline(PlacementInfoSearchRequest request) {
        BizCheckUtil.checkNotNull(request, "请求参数不能为空");
        request.setSoldierId(SessionUtils.getSoldierUserId());

        return placementSoldierInfoConsumer.viewDeadline(request);
    }

    @Override
    public BaseResponse<PlacementSoldierInfoDTO> getFilteredSoldierDetail() {
        return placementSoldierInfoConsumer.getFilteredSoldierDetail(SessionUtils.getSoldierUserId());

    }

    @Override
    public BaseResponse<Integer> confirmBaseInfo(PlacementSoldierInfoUpdateRequest request) {

        BizCheckUtil.checkNotNull(request, "请求参数不能为空");
        request.setSoldierId(SessionUtils.getSoldierUserId());

        return placementSoldierInfoConsumer.confirmBaseInfo(request);
    }

    @Override
    public BaseResponse<Integer> updateSoldierInfoBySoldier(PlacementSoldierInfoUpdateRequest request) {
        BizCheckUtil.checkNotNull(request, "请求不能为空");
        request.setSoldierId(SessionUtils.getSoldierUserId());
        return placementSoldierInfoConsumer.updateSoldierInfoBySoldier(request);
    }

    @Override
    public BaseResponse<Integer> representArchiveScore(CommonRepresentationRecordInsertRequest request) {

        BizCheckUtil.checkNotNull(request, "请求参数不能为空");
        request.setSoldierId(SessionUtils.getSoldierUserId());
        return placementSoldierInfoConsumer.representArchiveScore(request);
    }
}
